package com.copro.chemdb.stat;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.ihelpuoo.lang.NumericUtils;

import com.copro.chemdb.subject.Subject;
import com.copro.chemdb.subject.SubjectUtils;
import com.copro.simple.Application;
import com.copro.simple.SimpleException;

public class ListStatSubjectAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Application app = Application.me(request);
		int quesId = NumericUtils.parseInt(request.getParameter("quesId"), -1);
		if (quesId <= 0)
			throw new SimpleException("Questionnaire ID must more than 1 !!!");
		List<Subject> subjects = SubjectUtils.queryStatSubjects(app, quesId);
		request.setAttribute("items", subjects);
		return mapping.findForward("subjects");
	}

}
